<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>热表厂技能矩阵统计看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-form-item {
      margin-bottom: 0px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <vue2-board-header :title="'热表厂技能矩阵统计看板'"></vue2-board-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="组织结构:">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:400px;">
          </el-cascader>
        </el-form-item>

        <el-form-item label="指标类型:">
          <el-select v-model="queryInfo.skilltype" placeholder="请选择" filterable clearable>
            <el-option v-for="i in skillTypeList" :key="i" :label="i" :value="i">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="指标名称:">
          <el-input v-model.trim="queryInfo.skilltargetname" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="姓名:">
          <el-input v-model.trim="queryInfo.fullname" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <div id="datagrid" style="margin-top: 10px;" class="custom-scrollable-element">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border ref="table">
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="姓名" prop="fullname" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="头像" width="70">
            <template slot-scope="scope">
              <div v-if="scope.row.userimageurl">
                <el-image style="width:48px;height: 48px;" :src="scope.row.userimageurl"
                  :preview-src-list="[scope.row.userimageurl]">
                </el-image>
              </div>
              <div v-else>
                <el-image style="width:48px;height: 48px;" :src="'../images/person_blue.png'"></el-image>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="组织结构" prop="orginfo" width="300" show-overflow-tooltip></el-table-column> -->
          <el-table-column label="总分" prop="totalscore" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="通用类" align="center" v-if="this.commomColums.length > 0">
            <el-table-column v-for="key in commomColums" :label="key" :key="key" :prop="key" align="center" width="100">
              <template slot-scope="scope">
                <div v-if="scope.row[key].value !== '/'">
                  <el-progress width="68" stroke-width="10" type="circle" :color="scope.row[key].color"
                    :percentage="scope.row[key].value">
                  </el-progress>
                </div>
                <div v-else>
                  /
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="实操类" align="center" v-if="this.operateColums.length > 0">
            <el-table-column v-for="key in operateColums" :label="key" :key="key" :prop="key" align="center"
              width="100">
              <template slot-scope="scope">
                <div v-if="scope.row[key].value !== '/'">
                  <el-progress width="68" stroke-width="10" type="circle" :color="scope.row[key].color"
                    :percentage="scope.row[key].value">
                  </el-progress>
                </div>
                <div v-else>
                  /
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="专用类" align="center" v-if="this.specialColums.length > 0">
            <el-table-column v-for="key in specialColums" :label="key" :key="key" :prop="key" align="center"
              width="100">
              <template slot-scope="scope">
                <div v-if="scope.row[key].value !== '/'">
                  <el-progress width="68" stroke-width="10" type="circle" :color="scope.row[key].color"
                    :percentage="scope.row[key].value">
                  </el-progress>
                </div>
                <div v-else>
                  /
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>

        <!-- 分页组件 -->
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="total">
        </el-pagination>
      </div>
      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import Vue2BoardHeader from '../Scripts/components/Vue2BoardHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2BoardHeader },
      data: {
        queryInfo: {
          selectOrg: '',
          skilltargetname: '',
          skilltype: '',
          fullname: '',
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        orginazition: [],
        baseApi: '../handler/board/RbSkillTargetBoard.ashx',
        colums: [],
        commomColums: [],//通用类
        operateColums: [],//实操类
        specialColums: [],//专用类
        skillTypeList: ['通用类', '实操类', '专用类']
      },
      methods: {
        //查询数据
        async getData() {
          this.loading = true;
          const { data: { data, meta, total } } = await axios.post(`${this.baseApi}?action=getData`, {
            ...this.queryInfo,
            type: 'getData'
          })

          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.total = total;
          this.dataList = data;

          this.colums = [];
          this.commomColums = [];
          this.operateColums = [];
          this.specialColums = [];

          for (const key in data[0]) {
            const list = ['fullname', 'orginfo', 'employeeid', 'employeename', 'liuwei', 'totalscore', 'userimageurl'];
            if (list.some(i => i === key)) {
              continue;
            }
            this.colums.push(key);
            const { name } = data[0][key];
            switch (name) {
              case "通用类":
                this.commomColums.push(key);
                break;
              case "实操类":
                this.operateColums.push(key);
                break;
              case "专用类":
                this.specialColums.push(key);
                break;
              default:
                break;
            }
          }

          for (const item of data) {
            for (const key in item) {
              if (item.hasOwnProperty(key) && this.colums.includes(key)) {
                const value = item[key].value ? parseInt(item[key].value) : '/';
                let color = '';
                switch (value) {
                  case 25:
                    color = '#F00';
                    break;
                  case 50:
                    color = '#E6A23C';
                    break;
                  case 75:
                    color = '#409EFF';
                    break;
                  case 100:
                    color = '#67C23A';
                    break;
                  default:
                    break;
                }
                item[key] = { value, color }
              }
            }
          }
          this.$refs["table"].doLayout();
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
      },
      async mounted() {
        this.orginazition = await getMESOrginazition({ isMapping: '是', factoryCode: '602', wctype: '是' });
        this.getData();
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>